/**
 * Created by weirdor on 2017/12/28.
 */
var Menu = {
    id: "menuTable",
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
Menu.initColumn = function () {
    var columns = [
        {
            field: 'selectItem',
            radio: true
        },
        {
            field: 'id',
            title: 'ID',
            align: 'center',
            valign: 'middle',
            width: '60px'
        },
        {
            field: 'name',
            title: '权限名称',
            align: 'center',
            valign: 'middle'
        },
        {
            field: 'icon',
            title: '图标',
            align: 'center',
            valign: 'middle',
            formatter: function(item, index) {
                return item.icon == null ? '' : '<i class="layui-icon">'+item.icon+'</i>';
            }
        },
        {
            field: 'type',
            title: '类型',
            align: 'center',
            valign: 'middle',
            formatter: function(item, index) {
                if(item.type === 0){
                    return '<span class="label label-primary">目录</span>';
                }
                if(item.type === 1){
                    return '<span class="label label-success">菜单</span>';
                }
                if(item.type === 2){
                    return '<span class="label label-warning">按钮</span>';
                }
            }
        },
        {
            field: 'sort',
            title: '排序号',
            align: 'center',
            valign: 'middle'
        },
        {
            field: 'url',
            title: '权限URL',
            align: 'center',
            valign: 'middle'
        },
        {
            field: 'permCode',
            title: '权限编码',
            align: 'center',
            valign: 'middle'
        },
        {
            field: 'status',
            title: '状态',
            align: 'center',
            valign: 'middle',
            formatter: function(item, index){
                if (item.status == 0) {
                    return '<span class="label label-danger">禁用</span>';
                } else if (item.status == 1) {
                    return '<span class="label label-primary">启用</span>';
                }
                return "<span>其他</span>";
            }
        }
    ]
    return columns;
};

$(function () {

    var colunms = Menu.initColumn();
    var table = new TreeTable(Menu.id, "/shiro/permission/getList", colunms);
    table.setExpandColumn(2);
    table.setIdField("id");
    table.setCodeField("id");
    table.setParentCodeField("pid");
    table.setExpandAll(false);
    table.init();
    Menu.table = table;

});